//=============================================================================
// DirectInput.h
//
// Wraps initialization of immediate mode Direct Input, and provides 
// information for querying the state of the keyboard and mouse.
//=============================================================================
#pragma once

#ifndef _XBOX_CONTROLLER_H_
#define _XBOX_CONTROLLER_H_
//No MFC
#define _WIN32_LEAN_AND_MEAN
#define XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE 7849
#define XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE 8689
#define VMAX 65535
#define DIRECTINPUT_VERSION 0x0800
#define XINPUT_MAX_ANALOG 32767
#include <dinput.h>
#include <Windows.h>
#include <XInput.h>

#pragma comment(lib, "Xinput.lib")

enum ControllerInput
{
	XINPUT_CONTROLLER_UP			= 0x0001,
	XINPUT_CONTROLLER_DOWN			= 0x0002,
	XINPUT_CONTROLLER_RIGHT			= 0x0004,
	XINPUT_CONTROLLER_LEFT			= 0x0008,
	XINPUT_CONTROLLER_START			= 0x0010,
	XINPUT_CONTROLLER_BACK			= 0x0020,
	XINPUT_CONTROLLER_LEFT_THUMB	= 0x0040,
	XINPUT_CONTROLLER_RIGHT_THUMB	= 0x0080,
	XINPUT_CONTROLLER_LEFT_SHOULDER	= 0x0100,
	XINPUT_CONTROLLER_RIGHT_SHOULDER= 0x0200,
	XINPUT_CONTROLLER_A				= 0x1000,
	XINPUT_CONTROLLER_B				= 0x2000,
	XINPUT_CONTROLLER_X				= 0x4000,
	XINPUT_CONTROLLER_Y				= 0x8000
};

class DirectInput
{
public:
	DirectInput(DWORD keyboardCoopFlags, DWORD mouseCoopFlags);
	~DirectInput();

	void poll();
	bool keyDown(unsigned char key);
	bool mouseButtonDown(int button);
	float mouseDX();
	float mouseDY();
	float mouseDZ();
	bool IsConnected();
	void Vibrate(short PlayerID = 0, int leftVal = 0, int rightVal = 0);

	XINPUT_STATE* GetControllerStatePointer(short PlayerID);

private:
	// Make private to prevent copying of members of this class.
	DirectInput(const DirectInput& rhs);
	DirectInput& operator=(const DirectInput& rhs);
		
private:
	IDirectInput8*       mDInput;

	IDirectInputDevice8* mKeyboard;
	char                 mKeyboardState[256]; 

	IDirectInputDevice8* mMouse;
	DIMOUSESTATE2        mMouseState;

	short PlayerNumber[4];	

public:
	XINPUT_STATE ControllerState[4];
};
extern DirectInput* gDInput;
extern CDirectXFramework* gd3dApp;

#endif